package com.wzt.greenhouse.model;

import java.util.ArrayList;
import java.util.List;

import com.wzt.greenhousemobile.CourseBean;
import com.wzt.greenhousemobile.GHInfoActivity;
import com.wzt.greenhousemobile.R;
import android.widget.TextView;

public class GreenhouseControl{
	String name;
	public List<MonitorBox> monitors;
	public List<ControlInfo> controls;
	private GetData infoGetData=null,controlGetData=null;
	private ControlTitle title =null;
	private String dangerid = null;
	private boolean isInit = false;
	public GreenhouseControl(String strName,String id) {
		// TODO Auto-generated constructor stub
		name = strName;
		this.dangerid = id;
		monitors = new ArrayList<MonitorBox>();
		controls = new ArrayList<ControlInfo>();
	}
	
	public String getDangerid() {
		return dangerid;
	}
	
	public String getName() {
		return name;
	}
	
	public void setDangerid(String dangerid) {
		this.dangerid = dangerid;
	}
	
	public boolean AddMonitorBox(MonitorBox box)
	{
		return monitors.add(box);
	}
	
	public boolean AddControl(ControlInfo info)
	{
		return controls.add(info);
	}
	
	public int getMonistorCount()
	{
		return monitors.size();
	}
	
	public int getControlInfoCount()
	{
		return controls.size();
	}
	
	public MonitorBox getMonitorBox(int index)
	{
		return monitors.get(index);
	}
	
	public ControlInfo getControlInfo(int index)
	{
		return controls.get(index);
	}
	
	public GetData getInfoGetData() {
		return infoGetData;
	}
	
	public GetData getControlGetData() {
		return controlGetData;
	}
	
	public void setInfoGetData(GetData infoGetData) {
		this.infoGetData = infoGetData;
	}
	
	public void setControlGetData(GetData controlGetData) {
		this.controlGetData = controlGetData;
	}
	
	public ControlTitle getTitle() {
		return title;
	}
	
	public void setTitle(ControlTitle title) {
		this.title = title;
	}
	
	public ControlInfo getControlInfoById(String id)
	{
		for(int i=0 ; i<controls.size() ; i++)
		{
			ControlInfo info = controls.get(i);
			if(info.getId().equals(id))
			{
				return info;
			}
		}
		return null;
	}
	
	public MonitorBox getMonitorBoxById(String id)
	{
		for (int i = 0; i < monitors.size(); i++) {
			MonitorBox box = monitors.get(i);
			if(box.getId().equals(id))
			{
				return box;
			}
		}
		return null;
	}
	
	public boolean isInit()
	{
		return this.isInit;
	}
	
	public void setInit()
	{
		this.isInit = true;
	}

	public void RefreshMonistorState() {
		for(int i=0 ;i<this.getMonistorCount();i++)
		{
			MonitorBox box = getMonitorBox(i);
			for(int n=0; n<box.getSize(); n++)
			{
				MonitorInfo info = box.GetInfoForIndex(0);
				CourseBean cBean = GHInfoActivity.infoMap.get(info);
				if(cBean.getConvertView()==null)
					continue;
				TextView stateView = (TextView) cBean.getConvertView().findViewById(R.id.MState);
				stateView.setText(info.getValue());
				
			}
		}
	}
}
